<template>
  <div>
    <!-- 只有非登录页显示菜单 -->
    <el-container v-if="$route.path !== '/login' && $route.path !== '/register'" style="height: 100vh; display: flex; flex-direction: column;">
      <el-header>
        <el-menu :default-active="$route.path" mode="horizontal" @select="onMenuSelect">
          <el-menu-item index="/test">MBTI测试</el-menu-item>
          <el-menu-item index="/result">我的结果</el-menu-item>
          <el-menu-item index="/students">学生管理</el-menu-item>
          <el-menu-item index="/majors">专业管理</el-menu-item>
          <el-menu-item index="/colleges">学院管理</el-menu-item>
          <el-menu-item index="/logout">退出登录</el-menu-item>
        </el-menu>
      </el-header>

      <el-main style="flex: 1; overflow-y: auto;">
        <router-view />
      </el-main>
    </el-container>

    <!-- 登录页或注册页直接显示内容，无菜单 -->
    <div v-else>
      <router-view />
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    onMenuSelect(index) {
      if (index === '/logout') {
        localStorage.removeItem('loggedIn');
        localStorage.removeItem('studentInfo');
        this.$router.push('/login');
      } else {
        this.$router.push(index);
      }
    },
  },
}
</script>
